﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Com.ThrongIn.BE;
using Com.ThrongIn.BLL;
namespace ThrongIn.UserControls
{
    public partial class BreadCrumb : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["cid"] != null)
                {
                    Int64 pid= -1;
                    if (Int64.TryParse(Convert.ToString(Request.QueryString["cid"]), out pid))
                    {
                        if (pid != -1)
                        {
                            lblBreadCrum.Text = CreateBreadCrumb(pid);
                        }
                    }
                }
            }
        }

        private string CreateBreadCrumb(Int64 pid)
        {
            List<Category> categoryList = new CategoryBLL().GetCategoryForBreadCrumb(pid);
            string bCrumb = String.Empty;
            StringBuilder breadCrumb = new StringBuilder();
            breadCrumb.Append("<UL><LI><a class='author' href='Index.aspx'>Home</a></LI>");
            if (categoryList != null && categoryList.Count() > 0)
            {
                categoryList.OrderByDescending(c => c.Rank);
                int i = 0, count = categoryList.Count();
                foreach (Category category in categoryList)
                {
                    i++;
                   if(i!=count)
                        breadCrumb.Append("<LI><a class='author' href='" + "Profiles.aspx" + "?cid=" + category.Category_Mst_Id + "'>" + category.Category_Name + "</a></LI>");
                    else
                        breadCrumb.Append("<LI class='current'><a class='author' href='" + "Profiles.aspx" + "?cid=" + category.Category_Mst_Id + "'>" + category.Category_Name + "</a></LI>");
                }    
                breadCrumb.Append("</UL>");

                bCrumb = breadCrumb.ToString();
                
            }
            /*
             * <ul class="xbreadcrumbs" id="breadcrumbs-1">
	            <li>
	               <a href="#" class="home">Home</a>
	            </li>
	            <li>
	               <a href="#">Mobiles</a>
	            </li>
	            <li>
	               <a href="#">Nokia</a>
	            </li>
	            <li class="current"><a href="#">Nokia Lumia 800</a></li>
	    </ul>

             */
            return bCrumb;
        }
    }
}